<template>
  <div class="main-layout">
    <el-container>
      <el-container>
        <el-header>
          <div class="header-left">
            <el-breadcrumb>
              <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item>{{ currentRoute }}</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <div class="header-right">
            <el-dropdown>
              <span class="user-info">
                <el-avatar :size="32" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
                <span>管理员</span>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>个人信息</el-dropdown-item>
                  <el-dropdown-item>修改密码</el-dropdown-item>
                  <el-dropdown-item divided>退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
        <el-footer>
          <el-menu
            :default-active="activeMenu"
            mode="horizontal"
            :router="true"
            class="bottom-nav"
          >
            <el-menu-item index="/dashboard">
              <el-icon><Monitor /></el-icon>
              <span>监控</span>
            </el-menu-item>
            <el-menu-item index="/prediction">
              <el-icon><DataLine /></el-icon>
              <span>预测</span>
            </el-menu-item>
            <el-menu-item index="/alerts">
              <el-icon><Bell /></el-icon>
              <span>预警</span>
            </el-menu-item>
            <el-menu-item index="/devices">
              <el-icon><Cpu /></el-icon>
              <span>设备</span>
            </el-menu-item>
            <el-menu-item index="/settings">
              <el-icon><Setting /></el-icon>
              <span>设置</span>
            </el-menu-item>
          </el-menu>
        </el-footer>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import {
  Monitor,
  DataLine,
  Bell,
  Cpu,
  Setting
} from '@element-plus/icons-vue'

const route = useRoute()

const activeMenu = computed(() => route.path)
const currentRoute = computed(() => {
  const routeMap: Record<string, string> = {
    '/dashboard': '监控',
    '/prediction': '预测',
    '/alerts': '预警',
    '/devices': '设备',
    '/settings': '设置'
  }
  return routeMap[route.path] || ''
})
</script>

<style scoped>
.main-layout {
  height: 100vh;
}

.el-container {
  height: 100%;
}

.el-header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 50px;
}

.header-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.user-info span {
  margin-left: 8px;
  font-size: 14px;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
  height: calc(100vh - 100px);
  overflow-y: auto;
}

.el-footer {
  padding: 0;
  height: 50px;
  background-color: #fff;
  border-top: 1px solid #e6e6e6;
}

.bottom-nav {
  height: 100%;
  display: flex;
  justify-content: space-around;
  border: none;
}

.bottom-nav .el-menu-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0;
}

.bottom-nav .el-menu-item .el-icon {
  margin-right: 0;
  margin-bottom: 2px;
  font-size: 20px;
}

.bottom-nav .el-menu-item span {
  font-size: 12px;
}

:deep(.el-menu--horizontal) {
  border-bottom: none;
}

:deep(.el-menu--horizontal > .el-menu-item.is-active) {
  border-bottom: 2px solid var(--el-color-primary);
}
</style> 